home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / src / expires.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-06  |  3.9 KB  |  157 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: expires.c,v 5.2 1992/12/07 02:58:56 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
  6.  *
  7.  *            Copyright (c) 1988-1992 USENET Community Trust
  8.  *            Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: expires.c,v $
  17.  * Revision 5.2  1992/12/07  02:58:56  syd
  18.  * Fix long -> time_t
  19.  * From: Syd
  20.  *
  21.  * Revision 5.1  1992/10/03  22:58:40  syd
  22.  * Initial checkin as of 2.4 Release at PL0
  23.  *
  24.  *
  25.  ******************************************************************************/
  26.  
  27. /** This routine is written to deal with the Expires: header on the
  28.     individual mail coming in.  What it does is to look at the date,
  29.     compare it to todays date, then set the EXPIRED flag on the
  30.     current message if it is true...
  31. **/
  32.  
  33. #include "headers.h"
  34.  
  35. #ifdef I_TIME
  36. #  include <time.h>
  37. #endif
  38. #ifdef I_SYSTIME
  39. #  include <sys/time.h>
  40. #endif
  41.  
  42. #include <ctype.h>
  43.  
  44. #ifdef BSD
  45. #undef toupper
  46. #undef tolower
  47. #endif
  48.  
  49. process_expiration_date(date, message_status)
  50. char *date;
  51. int  *message_status;
  52. {
  53.     struct tm *timestruct;
  54.     time_t thetime;
  55.     char word1[WLEN], word2[WLEN], word3[WLEN], word4[WLEN], word5[WLEN];
  56.     int  month = 0, day = 0, year = 0, hour = 0, minute = 0;
  57. #ifndef    _POSIX_SOURCE
  58.     struct tm *localtime();
  59.     time_t time();
  60. #endif
  61.  
  62.     /** first step is to break down the date given into MM DD YY HH MM
  63.         format:  The possible formats for this field are, by example:
  64.     
  65.         (1) Mon, Jun 11, 87
  66.         (2) Mon, 11 Jun 87
  67.         (3) Jun 11, 87
  68.         (4) 11 Jun 87
  69.         (5) 11/06/87    <- ambiguous - will be ignored!!
  70.         (6) 8711061248GMT
  71.         (7) Mon, Jun 11, 87 12:48:35 GMT
  72.  
  73.         The reason #5 is considered ambiguous will be made clear
  74.         if we consider a message to be expired on Jan 4, 88:
  75.             01/04/88    in the United States
  76.             04/01/88    in Europe
  77.         so is the first field the month or the day?  Standard prob.
  78.     **/
  79.  
  80.     sscanf(date, "%s %s %s %s %s",
  81.         word1, word2, word3, word4, word5);
  82.  
  83.     if (strlen(word5) != 0) {    /* we have form #7 */
  84.       day   = atoi(word1);
  85.       month = month_number(word2);
  86.       year  = atoi(word3);
  87.       sscanf(word4, "%02d%*c%02d",
  88.            &hour, &minute);
  89.     }
  90.     else if (strlen(word2) == 0) {    /* we have form #6 or form #5 */
  91.       if (isdigit(word1[1]) && isdigit(word1[2]))      /* form #6 */
  92.         sscanf(word1, "%02d%02d%02d%02d%02d%*c",
  93.          &year, &month, &day, &hour, &minute);
  94.     }
  95.     else if (strlen(word4) != 0) {           /* form #1 or form #2 */
  96.       if(isdigit(word2[0])) {           /* form #2 */
  97.           month = month_number(word3);
  98.           day   = atoi(word2);
  99.           year  = atoi(word4);
  100.       } else {                   /* form #1 */
  101.           month = month_number(word2);
  102.           day   = atoi(word3);
  103.           year  = atoi(word4);
  104.       }
  105.     }
  106.     else if (! isdigit(word1[0])) {           /* form #3 */
  107.       month = month_number(word1);
  108.       day   = atoi(word2);
  109.       year  = atoi(word3);
  110.     }
  111.     else {                       /* form #4 */
  112.       day   = atoi(word1);
  113.       month = month_number(word2);
  114.       year  = atoi(word3);
  115.     }
  116.  
  117.     if (day == 0 || year == 0)
  118.       return;            /* we didn't get a valid date */
  119.  
  120.     /** next let's get the current time and date, please **/
  121.  
  122.     thetime = time((time_t *) 0);
  123.  
  124.     timestruct = localtime(&thetime);
  125.  
  126.     /** and compare 'em **/
  127.  
  128.     if (year > timestruct->tm_year)
  129.       return;
  130.     else if (year < timestruct->tm_year)
  131.       goto expire_message;
  132.  
  133.     if (month > timestruct->tm_mon)
  134.       return;
  135.     else if (month < timestruct->tm_mon)
  136.       goto expire_message;
  137.  
  138.     if (day > timestruct->tm_mday)
  139.       return;
  140.     else if (day < timestruct->tm_mday)
  141.       goto expire_message;
  142.  
  143.     if (hour > timestruct->tm_hour)
  144.       return;
  145.     else if (hour < timestruct->tm_hour)
  146.       goto expire_message;
  147.  
  148.     if (minute > timestruct->tm_min)
  149.       return;
  150.  
  151. expire_message:
  152.  
  153.     /** it's EXPIRED!  Yow!! **/
  154.  
  155.     (*message_status) |= EXPIRED;
  156. }
  157.